#!/usr/bin/env bash

set -e

# TODO: delete this script, the entry in `package.json`, and the subcommand in
# `Procfile` - it's only used for the Graphile Starter demo.

if [ "x$DEMO" != "xWIPE_DATABASE" ]; then
  echo "This script is only intended to be used when deploying the Graphile Starter demo to Heroku, since we reset the database every time we push. You should delete it and delete the references to it in package.json and Procfile."
  exit 0;
fi;

if [ "x$DATABASE_URL" = "x" ]; then
  echo "No database URL.";
  exit 2;
fi;

psql "$DATABASE_URL" <<HERE
  DROP SCHEMA IF EXISTS graphile_migrate, graphile_worker, app_public, app_hidden, app_private CASCADE;
HERE

# Reinstall the worker schema
yarn workspace @app/worker install-db-schema
